package com.example.majiang.util;

import com.example.majiang.mapper.UserMappper;
import com.example.majiang.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.http.Cookie;

@Component
public class UserUtil {
    @Autowired
    private  UserMappper userMappper;
    public User findUser(Cookie[]cookies){
        if(cookies==null||cookies.length==0){
            return null;
        }
        User user=null;
        for(Cookie cookie:cookies){
            if(cookie.getName().equals("token")){
                String token=cookie.getValue();
                user=userMappper.findByToken(token);
                if(user!=null){
                   break;
                }

            }
        }
        return user;
    }
}
